package com.wzdigit.wms.wms.controller.TransferWareHouse;

import com.wzdigit.framework.exception.RestStatusException;
import com.wzdigit.framework.model.response.ErrorEntity;
import com.wzdigit.wms.basic.client.Pager;
import com.wzdigit.wms.basic.client.PagerInfo;
import com.wzdigit.wms.basic.client.request.transfer.SearchGdnHeaderReportRequest;
import com.wzdigit.wms.basic.client.response.gdn.other.SimpleGdnReportRequest;
import com.wzdigit.wms.basic.client.response.transfer.GdnDtlGoodsReportResponse;
import com.wzdigit.wms.basic.client.response.transfer.GdnDtlReportResponse;
import com.wzdigit.wms.basic.client.response.transfer.GdnHeaderReportResponse;
import com.wzdigit.wms.wms.constant.WmsWareConstant;
import com.wzdigit.wms.wms.service.transfer.GdnReportService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * <p>
 * 出库报表-- 前端控制器
 * </p>
 *
 * @author
 * @since 2021-01-12
 */
@RestController
@Api(tags = "出库报表")
@RequestMapping(value = WmsWareConstant.API_VERSION)
public class GdnReportController {

	public static final String REQUEST_MODEL = "/gdnreport";

	@Autowired
	private GdnReportService gdnReportService;

	/**
	 * 出库报表-主档查询
	 * 
	 * @param dto
	 * @param pager
	 * @param servletRequest
	 * @param servletResponse
	 * @return
	 */
	@ApiOperation(value = "出库报表-主档查询", notes = "出库报表-主档查询")
	@ApiResponses({ @ApiResponse(code = 500, message = "系统出现异常", response = ErrorEntity.class) })
	@GetMapping(value = REQUEST_MODEL + "/selectGdnHeaderReportList")
	public <T> PagerInfo<List<GdnHeaderReportResponse>> selectGdnHeaderReportList(
			SearchGdnHeaderReportRequest dto, Pager<T> pager, 
			HttpServletRequest servletRequest, HttpServletResponse servletResponse) {
		try {
			return gdnReportService.selectGdnHeaderReportList(dto, pager);
		} catch (RestStatusException e) {
			e.printStackTrace();
			servletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
			throw e;
		}
	}

	/**
	 * 出库报表-明细查询
	 * 
	 * @param request
	 * @param servletRequest
	 * @param servletResponse
	 * @return
	 */
	@ApiOperation(value = "出库报表-明细查询", notes = "出库报表-明细查询")
	@ApiResponses({ @ApiResponse(code = 500, message = "系统出现异常", response = ErrorEntity.class) })
	@GetMapping(value = REQUEST_MODEL + "/selectGdnDtlReportList")
	public List<GdnDtlReportResponse> selectGdnDtlReportList(
			SimpleGdnReportRequest request,
			HttpServletRequest servletRequest, HttpServletResponse servletResponse) {
		try {
			return gdnReportService.selectGdnDtlReportList(request.getGdnHeaderId(),
					request.getBeginDate(), request.getEndDate());
		} catch (RestStatusException e) {
			e.printStackTrace();
			servletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
			throw e;
		}
	}

	/**
	 * 出库报表-明细货品清单查询
	 * 
	 * @param gdnHeaderId
	 * @param pager
	 * @param servletRequest
	 * @param servletResponse
	 * @return
	 */
	@ApiOperation(value = "出库报表-明细货品清单查询", notes = "出库报表-明细货品清单查询")
	@ApiResponses({ @ApiResponse(code = 500, message = "系统出现异常", response = ErrorEntity.class) })
	@GetMapping(value = REQUEST_MODEL + "/selectGdnDtlGoodsReportList")
	public <T> PagerInfo<List<GdnDtlGoodsReportResponse>> selectGdnDtlGoodsReportList(
			@ApiParam(value = "发货单表头ID", required = true) 
			@RequestParam(required = true) Long gdnHeaderId,
			Pager<T> pager, HttpServletRequest servletRequest, 
			HttpServletResponse servletResponse) {
		try {
			return gdnReportService.selectGdnDtlGoodsReportList(gdnHeaderId, pager);
		} catch (RestStatusException e) {
			e.printStackTrace();
			servletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
			throw e;
		}
	}

	/**
	 * 导出明细货品清单
	 * 
	 * @param gdnHeaderId
	 * @param servletRequest
	 * @param servletResponse
	 * @return
	 * @throws Exception
	 */
	@ApiOperation(value = "导出明细货品清单", notes = "导出明细货品清单")
	@ApiResponses({ @ApiResponse(code = 500, message = "系统出现异常", response = ErrorEntity.class) })
	@GetMapping(value = REQUEST_MODEL + "/exportGdnDtlGoodsReportList")
	public void exportGdnDtlGoodsReportList(
			@ApiParam(value = "发货单表头ID", required = true) 
			@RequestParam(required = true) Long gdnHeaderId,
			HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws Exception {
		try {
			gdnReportService.exportGdnDtlGoodsReportList(gdnHeaderId, servletRequest, servletResponse);
		} catch (RestStatusException e) {
			e.printStackTrace();
			servletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
			throw e;
		}
	}

	/**
	 * 导出主档和明细
	 * 
	 * @param
	 * @param servletRequest
	 * @param servletResponse
	 * @return
	 * @throws Exception
	 */
	@ApiOperation(value = "导出主档和明细", notes = "导出主档和明细")
	@ApiResponses({ @ApiResponse(code = 500, message = "系统出现异常", response = ErrorEntity.class) })
	@GetMapping(value = REQUEST_MODEL + "/exportGdnGdnHeaderAndDtlReportList")
	public void exportGdnGdnHeaderAndDtlReportList(SearchGdnHeaderReportRequest dto, 
			HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws Exception {
		try {
			gdnReportService.exportGdnGdnHeaderAndDtlReportList(dto, servletRequest, servletResponse);
		} catch (RestStatusException e) {
			e.printStackTrace();
			servletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
			throw e;
		}
	}
}
